package com.topwalk.datacollect.dao.imp;

import com.topwalk.datacollect.dao.TRegBizinfListDao;
import com.topwalk.datacollect.model.TRegBizinfList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import java.sql.ResultSet;
import java.sql.SQLException;

@Repository
public class TRegBizinfListDaoImpl implements TRegBizinfListDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    class TRegBizinfListDaoRowMapper implements RowMapper<TRegBizinfList>{

        @Override
        public TRegBizinfList mapRow(ResultSet resultSet, int i) throws SQLException {
            TRegBizinfList tRegBizinfList = new TRegBizinfList();
            tRegBizinfList.setPlatId(resultSet.getString("platID"));
            tRegBizinfList.setInnerLinkId(resultSet.getString("innerLinkID"));
            tRegBizinfList.setBizId(resultSet.getString("bizID"));
            tRegBizinfList.setBizManageDepart(resultSet.getString("bizManageDepart"));
            tRegBizinfList.setBizName(resultSet.getString("bizName"));
            tRegBizinfList.setBizTypeCode(resultSet.getString("bizTypeCode"));
            tRegBizinfList.setBizOperateStyleCode(resultSet.getString("bizOperateStyleCode"));
            tRegBizinfList.setManageDepartManager(resultSet.getString("manageDepartManager"));
            tRegBizinfList.setManagerPhone(resultSet.getString("managerPhone"));
            tRegBizinfList.setManagerMail(resultSet.getString("managerMail"));
            tRegBizinfList.setManagerOtherLink(resultSet.getString("managerOtherLink"));
            tRegBizinfList.setApproveUnit(resultSet.getString("approveUnit"));
            tRegBizinfList.setApproveTime(resultSet.getString("approveTime"));
            tRegBizinfList.setApproveNo(resultSet.getString("approveNo"));
            tRegBizinfList.setRegisterTime(resultSet.getString("registerTime"));
            tRegBizinfList.setDataExchangDirect(resultSet.getString("dataExchangDirect"));
            tRegBizinfList.setBaseProCode(resultSet.getString("baseProCode"));
            tRegBizinfList.setRealTime(resultSet.getString("realTime"));
            tRegBizinfList.setDataExchangDataFlux(resultSet.getString("dataExchangDataFlux"));
            tRegBizinfList.setIsBackup(resultSet.getString("isBackup"));
            tRegBizinfList.setBackupUnit(resultSet.getString("backupUnit"));
            tRegBizinfList.setCollectTime(resultSet.getString("collectTime"));

            return tRegBizinfList;
        }
    }


    @Override
    public TRegBizinfList findByBizInfoID(String bizInfoId) {
        String sql = "select * from t_reg_bizinf_list where bizID = ?";
        TRegBizinfList tRegBizinfList;
        try {
            tRegBizinfList = jdbcTemplate.queryForObject(sql, new TRegBizinfListDaoRowMapper(), bizInfoId);
        }catch (EmptyResultDataAccessException e){
            return null;
        }
        return tRegBizinfList;
    }
}
